#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-p path -l id_labdel -t target] ppid label'
exit 2
}

while getopts  ":p:f:l:t:" opt; do
	case  $opt  in
		p) path=$OPTARG;;
		f) suffix=$OPTARG;;
        l) label=$OPTARG;;
        t) target=$OPTARG;;
        i) ide=$OPTARG;;
        
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

if test -z "$ide"; then ide="ID"; fi
if test -z "$path"; then path=`pwd`; fi
if test -z "$label"; then label='running'; fi
if test -z "$target"; then target='/mnt/ilustre/app/medical/.pub/.mnt'; fi 

s_start=`date +%s`

time_start=`date +%m%d%H%M`


interv=30
path_tr_label='_slash.'
space_tr_label='.space.'


while true; do
	s_end=`date +%s`
	sh=`awk 'BEGIN{printf("%.1f", ("'$s_end'"-"'$s_start'")/60/60)}'`
	sh0=`awk 'BEGIN{printf("%d", "'$sh'")}'`
    # echo -e "\n `date +%c`\n $label $*, $sh0 hour(s) passed." >> $target/stat
    echo -e "$* $label.\t`date +%s`\t$sh0 hour(s) passed. `date +%c`\t$path\t$ide" >> $target/stat
    # touch $target/`echo $* |sed 's/\//'$path_tr_label'/g'|sed 's/ /'$space_tr_label'/g'`
    
    # echo -e "$*\t`date +%s`\t$sh0 hour(s) passed. `date +%c`\t$path\t$ide" >> $target/`echo ${*}.$ide |sed 's/\//'$path_tr_label'/g'|sed 's/ /'$space_tr_label'/g'`
    echo -e "$*\t`date +%s`\t$sh0 hour(s) passed. `date +%c`\t$path\t$ide" >> $target/$1.$$.$time_start.`hostname`.$2
    
    sleep $interv
    
done
